﻿

function changeLeftMenuToGray() {
    $(".corp_off").removeClass("corp_off").addClass("gray_corp_off");
    $(".expertise_off").removeClass("expertise_off").addClass("gray_expertise_off");
    $(".industries_off").removeClass("industries_off").addClass("gray_industries_off");
    $(".why_off").removeClass("why_off").addClass("gray_why_off");
    $(".contact-bar-white").removeClass("contact-bar-white").addClass("contact-bar-gray");
}

function setMouseOver2(object, newClass) {
    oldClass = object.className;
    object.className = newClass;

}

function setMouseOut2(object, newClass) {
    if (oldClass.indexOf('-on') < 0) {
        object.className = newClass;
    }
}

function keypressed(event) {
    if (event.keyCode == '13') {
        var p = document.getElementById("Hidden1");
        var q = document.getElementsByName('q')[0].value;
        var newWindow = window.open(p.value + q, '_self');
    }
}
function showsearch() {
    var q = document.getElementsByName('q')[0].value;
    var p = document.getElementById("Hidden1");
    var newWindow = window.open(p.value + q, '_self');
}

function fncLoaded() {
    ShowDiv("master_main_page", true);
    ShowDiv("master_main_loading", false);
}

function ShowDivById(divId, visible) {
    var divObject = document.getElementById(divId);
    if (divObject != null) {
        divObject.style.display = (visible) ? "block" : "none";
        divObject.style.visibility = (visible) ? "visible" : "hidden";
    }
}
function fncLoaded() {
    ShowDivById("master_main_page", true);
    ShowDivById("master_main_loading", false);
}

/*
From the parent object, show its submenu
*/
function ShowSub(object) {
    // hide all first
    HideAll();

    var parent_id = object.id;
    var menu_on = document.getElementById(parent_id + "_on");
    var menu_off = document.getElementById(parent_id + "_off");

    ShowDiv(menu_on, true);
    ShowDiv(menu_off, false);
}

function fixShowSub(parent_id)
{
    // hide all first
    HideAll();    
    var menu_on = document.getElementById(parent_id + "_on");
    var menu_off = document.getElementById(parent_id + "_off");

    ShowDiv(menu_on, true);
    ShowDiv(menu_off, false);
}
/*
From the parent id, show its submenu
*/
function ShowSub2(divid) {
    // hide all first
    HideAll();

    var menu_on = document.getElementById(divid + "_on");
    var menu_off = document.getElementById(divid + "_off");

    ShowDiv(menu_on, true);
    ShowDiv(menu_off, false);
}

/*
Does not work since "this" points to windows instead of the DIV itself
*/
function HideSub(object) {
    var parent_id = object.id;
    var menu_on = document.getElementById(parent_id + "_on");
    var menu_off = document.getElementById(parent_id + "_off");

    ShowDiv(menu_on, false);
    ShowDiv(menu_off, true);
}

function HideSub2(divid) {
    var menu_on = document.getElementById(divid + "_on");
    var menu_off = document.getElementById(divid + "_off");

    ShowDiv(menu_on, false);
    ShowDiv(menu_off, true);
}

function ShowDiv(divObject, visible) {
    if (divObject != null) {
        divObject.style.display = (visible) ? "block" : "none";
        divObject.style.visibility = (visible) ? "visible" : "hidden";
    }
}

function HideAll() {
    HideSub2("corp");
    HideSub2("expertise");
    HideSub2("industries");
    HideSub2("why");
}

function RestoreMenu() {
    if (activeMenu != "") {
        HideAll();
        ShowSub2(activeMenu);
    }
    /*
    else {
    var obj = document.getElementById('master_side');
    alert(obj);
    obj.className = "master-side-collapse";
    }
    */
}

function HighLightSub() {
    if (subMenuId != "") {
        //var id = "ctl00_" + subMenuId;
        var selector = "a[id$=" + subMenuId + "]";

        //var item = document.getElementById(id);
        var item = $(selector);

        if (item != null) {
            // item.className = "menu-item-active";
            //alert(item);
            item.addClass("menu-item-active");
        }
    }

}

/*********************************************************************
* Get an object, this function is cross browser
* *** Please do not remove this header. ***
* This code is working on my IE7, IE6, FireFox, Opera and Safari
* 
* Usage: 
* var object = get_object(element_id);
*
* @Author Hamid Alipour Codehead @ webmaster-forums.code-head.com		
**/


function get_object(id) {
    var object = null;
    if (document.layers) {
        object = document.layers[id];
    } else if (document.all) {
        object = document.all[id];
    } else if (document.getElementById) {
        object = document.getElementById(id);
    }
    return object;
}
/*********************************************************************/

/*********************************************************************
* No onMouseOut event if the mouse pointer hovers a child element 
* *** Please do not remove this header. ***
* This code is working on my IE7, IE6, FireFox, Opera and Safari
* 
* Usage: 
* <div onMouseOut="fixOnMouseOut(this, event, 'JavaScript Code');"> 
*		So many childs 
*	</div>
*
* @Author Hamid Alipour Codehead @ webmaster-forums.code-head.com		
**/
function is_child_of(parent, child) {
    if (child != null) {
        while (child.parentNode) {
            if ((child = child.parentNode) == parent) {
                return true;
            }
        }
    }
    return false;
}
function fixOnMouseOut(element, event, JavaScript_code) {
    var current_mouse_target = null;
    if (event.toElement) {
        current_mouse_target = event.toElement;
    } else if (event.relatedTarget) {
        current_mouse_target = event.relatedTarget;
    }
    if (!is_child_of(element, current_mouse_target) && element != current_mouse_target) {
        eval(JavaScript_code);
    }
}


// *** ONLOAD DOCUMENT

$("document").ready(function() {

    if (hasGrayBG == true) {
        changeLeftMenuToGray();
    }
    /*var obj = $('.tTip');
    alert(obj.attr("title");
    return;*/
    $('.tTip').betterTooltip({speed: 150, delay: 300});

});         